package com.hejia.alauda.persistence.mybatis;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.hejia.alauda.entity.HejiaRedPacketReceive;
import com.hejia.alauda.persistence.BaseMapper;

public interface HejiaRedPacketReceiveMapper extends BaseMapper<HejiaRedPacketReceive> {

	/**
	 * 删除合家红包领取
	 * @param hejiaRedPacketId 合家红包ID
	 * @return
	 */
	@Delete("delete from hejiaredpacketreceive where hejiaRedPacket_id = #{hejiaRedPacketId}")
	int deleteByHejiaRedPacketId(@Param("hejiaRedPacketId") Long hejiaRedPacketId);

	/**
	 * 统计用户已经领取的红包数
	 * @param userId	用户ID
	 * @param externalId	外部ID
	 * @return
	 */
	@Select("select count(r.id) from hejiaredpacket p join hejiaredpacketreceive r on r.hejiaRedPacket_id = p.id where p.externalId = #{externalId} and r.user_id = #{userId}")
	int countReceivedRedPacket(@Param("userId") Long userId, @Param("externalId") String externalId);
}
